//arm-unknown-linux-gnu-g++ -mcpu=arm9  -o fb_arm main.c socket.cpp

#include <unistd.h>
#include <sys/types.h>
#include <sys/mman.h>
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <assert.h>


#include "Firebot.h"
#include "socket.h"



//#pragma comment(lib, "ws2_32.lib")
//#include <winsock.h>
//#ifndef DEPLOYED
	//WSAData wsad;
//	WSAStartup(MAKEWORD(1,1), &wsad);

//#endif
//#include <process.h>

//#define dio1_base 0x80840004
//#define dio1dir_base 0x80840014



#ifndef __CYGWIN__

#include "TS7260IO.h"
//TS7260 Related declarations

//void init_ts7260_io();

//void sample_vex_module();

 
#endif

extern void loghex(char *what, unsigned char *buf, int length);
bool verbose_log; //verbose log of process() loops

int main(int argc, char **argv)
{
   try{
      
       printf("running...\n");
    //   clear();
       
       CFirebot firebot;
       
     //  CSocket woot;//*woot = new CSocket;
       //FBParser leet;
       
       unsigned char *buffer = NULL;
       int len = 0;
       
       while(1)
       {
          firebot.process(); //fb main loop + socket reading 
       }
   
} catch(...) {perror("Hella exception");}

   return 0;
}

/*
#ifndef  __CYGWIN__
void init_ts7260_io()
{   
  	      // upper nibble output, lower nibble input 
    return;
}
void sample_vex_module()
{
      #define pb ((*PBDR) & 1)
      
      int i;
      
      unsigned int samples[20];
     //  int i;
      unsigned int ct;
      
       for(i = 0; i < 20; i++)
       {
           //  state = pb;//edge detection
          ct = 0;
             while(1)
             {
                 do state = pb;
                 while(state == pb);
                 if(pb) break;
             }
             // while (!pb);
   
             // ct = 0;
              
               while(pb){ //falling edge
               
                  ct++;
                  if(ct == 0xFFFF) printf("overflow\n");
               }
              samples[i] = ct;
              
       }
       
       for(i = 0; i < 20; i++)
       {
             printf("%d  %d\n", i, samples[i]/10);
            // sleep(2);
       }
       sleep(2);
    //  *PEDR = 0xff;
      //sleep(1);
     // *PEDR = 0x00;
     // sleep(1);
}
#endif
*/
